/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UserInterface.Admin;

import Business.Launcher.Admin.LaunchAdmin;
import Business.Launcher.Launch;
import java.awt.event.WindowEvent;
import javax.swing.JOptionPane;


public class AdminJFrame extends javax.swing.JFrame {

    /**
     * Creates new form mainJFrame
     */
    public AdminJFrame() {
        initComponents();
        this.setLocationRelativeTo(null);
        this.setTitle("Final Project");
        this.setDefaultCloseOperation(AdminJFrame.EXIT_ON_CLOSE);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnGroupAnalysisType = new javax.swing.ButtonGroup();
        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel1 = new javax.swing.JPanel();
        passwordJT = new javax.swing.JPasswordField();
        jLabel2 = new javax.swing.JLabel();
        usernameJT = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        btnLogin = new javax.swing.JButton();
        container = new javax.swing.JPanel();
        lblWelcome = new javax.swing.JLabel();
        btnLogout = new javax.swing.JButton();
        btnAddRegions = new javax.swing.JButton();
        btnShow = new javax.swing.JButton();
        btnAnalysis = new javax.swing.JButton();
        rdoParticipantType = new javax.swing.JRadioButton();
        rdoEventType = new javax.swing.JRadioButton();
        rdoRegion = new javax.swing.JRadioButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(255, 255, 255));
        setPreferredSize(new java.awt.Dimension(437, 260));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jLabel2.setText("Password:");

        jLabel1.setText("Username:");

        btnLogin.setText("Login");
        btnLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLoginActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1)
                    .add(usernameJT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 110, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2)
                    .add(passwordJT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 110, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btnLogin, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 76, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(21, 21, 21)
                .add(jLabel1)
                .add(14, 14, 14)
                .add(usernameJT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(22, 22, 22)
                .add(jLabel2)
                .add(24, 24, 24)
                .add(passwordJT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(31, 31, 31)
                .add(btnLogin)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        jSplitPane1.setLeftComponent(jPanel1);

        container.setBackground(new java.awt.Color(204, 204, 255));
        container.setPreferredSize(new java.awt.Dimension(600, 600));

        lblWelcome.setText("welcom");

        btnLogout.setText("Logout");
        btnLogout.setEnabled(false);
        btnLogout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLogoutActionPerformed(evt);
            }
        });

        btnAddRegions.setText("Add Regions");
        btnAddRegions.setEnabled(false);
        btnAddRegions.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddRegionsActionPerformed(evt);
            }
        });

        btnShow.setText("Show Result");
        btnShow.setEnabled(false);
        btnShow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnShowActionPerformed(evt);
            }
        });

        btnAnalysis.setText("Analysis by");
        btnAnalysis.setEnabled(false);
        btnAnalysis.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAnalysisActionPerformed(evt);
            }
        });

        btnGroupAnalysisType.add(rdoParticipantType);
        rdoParticipantType.setText("Participant Type");

        btnGroupAnalysisType.add(rdoEventType);
        rdoEventType.setText("Event Type");

        btnGroupAnalysisType.add(rdoRegion);
        rdoRegion.setText("Countries");

        org.jdesktop.layout.GroupLayout containerLayout = new org.jdesktop.layout.GroupLayout(container);
        container.setLayout(containerLayout);
        containerLayout.setHorizontalGroup(
            containerLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(containerLayout.createSequentialGroup()
                .addContainerGap()
                .add(containerLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(containerLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                        .add(containerLayout.createSequentialGroup()
                            .add(lblWelcome, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 182, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                            .add(btnLogout))
                        .add(containerLayout.createSequentialGroup()
                            .add(btnAddRegions)
                            .add(27, 27, 27)
                            .add(btnShow, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .add(btnAnalysis, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 121, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(containerLayout.createSequentialGroup()
                        .add(rdoParticipantType)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(rdoEventType))
                    .add(rdoRegion))
                .addContainerGap(29, Short.MAX_VALUE))
        );
        containerLayout.setVerticalGroup(
            containerLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(containerLayout.createSequentialGroup()
                .addContainerGap()
                .add(containerLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblWelcome, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 34, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btnLogout))
                .add(46, 46, 46)
                .add(containerLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(btnAddRegions)
                    .add(btnShow))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(btnAnalysis)
                .add(18, 18, 18)
                .add(containerLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(rdoParticipantType)
                    .add(rdoEventType))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(rdoRegion)
                .addContainerGap(26, Short.MAX_VALUE))
        );

        jSplitPane1.setRightComponent(container);

        getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents
        private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoginActionPerformed
		String pass = new String(passwordJT.getPassword());
		if("admin".equals(usernameJT.getText()) && "admin".equals(pass)){
			btnLogin.setEnabled(false);
			btnLogout.setEnabled(true);
			btnAnalysis.setEnabled(true);
			btnAddRegions.setEnabled(true);
			btnShow.setEnabled(true);
			lblWelcome.setText("Welcome " + usernameJT.getText());
			usernameJT.setText("");
			passwordJT.setText("");
		}
        }//GEN-LAST:event_btnLoginActionPerformed

        private void btnLogoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLogoutActionPerformed
			btnLogin.setEnabled(true);
			btnLogout.setEnabled(false);
			btnAnalysis.setEnabled(false);
			btnAddRegions.setEnabled(false);
			btnShow.setEnabled(false);

        }//GEN-LAST:event_btnLogoutActionPerformed

        private void btnAddRegionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddRegionsActionPerformed
                // TODO add your handling code here:
			LaunchAdmin.showAddRegionJframe();
			this.setVisible(false);
        }//GEN-LAST:event_btnAddRegionsActionPerformed

        private void btnShowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowActionPerformed
			this.setVisible(false);
			LaunchAdmin.showResultJFrame();
                // TODO add your handling code here:
        }//GEN-LAST:event_btnShowActionPerformed

        private void btnAnalysisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAnalysisActionPerformed
			if(btnGroupAnalysisType.getSelection()== null){
				JOptionPane.showConfirmDialog(null, "Please choose analysis type",
					"Warning", JOptionPane.WARNING_MESSAGE);
				return;
			}
			if(rdoEventType.isSelected()){
				LaunchAdmin.showAnalysisFrame("event");
			}else if(rdoParticipantType.isSelected()){
				LaunchAdmin.showAnalysisFrame("participant");
			}else if(rdoRegion.isSelected()){
				LaunchAdmin.showAnalysisFrame("region");
			}
			this.setVisible(false);
        }//GEN-LAST:event_btnAnalysisActionPerformed
		
		protected void processWindowEvent(WindowEvent e){
			if(e.getID() == WindowEvent.WINDOW_CLOSING){
				LaunchAdmin.dispose();
				Launch.loginJFrame.setVisible(true);
			}else{
				super.processWindowEvent(e);
			}
		}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddRegions;
    private javax.swing.JButton btnAnalysis;
    private javax.swing.ButtonGroup btnGroupAnalysisType;
    private javax.swing.JButton btnLogin;
    private javax.swing.JButton btnLogout;
    private javax.swing.JButton btnShow;
    private javax.swing.JPanel container;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JLabel lblWelcome;
    private javax.swing.JPasswordField passwordJT;
    private javax.swing.JRadioButton rdoEventType;
    private javax.swing.JRadioButton rdoParticipantType;
    private javax.swing.JRadioButton rdoRegion;
    private javax.swing.JTextField usernameJT;
    // End of variables declaration//GEN-END:variables
}
